<?php

namespace App\Admin\RowActions;

use App\Services\CourService;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;

class CourseRefund extends RowAction
{
    protected $model;

    public function __construct(string $model = null)
    {
        $this->model = $model;
    }

    public function title()
    {
        return '<button class="btn btn-outline-info">原路退款</button>';
    }

    public function confirm()
    {
        return [
            "退款？",
            "该订单是否原路退回？"
        ];
    }

    public function handle(Request $request)
    {
        $ret = app(CourService::class)->refund($this->getKey());

        return $ret['status'] ? $this->response()->success('原路退回成功')->refresh() : $this->response()->error($ret['msg']);
    }

    public function parameters()
    {
        return [
            'model' => $this->model,
        ];
    }
}
